<?php

namespace App\Http\Controllers;

use App\Models\Student;
use Illuminate\Http\Request;

class StudentController extends Controller
{
    public function index(Request $request)
    {
        $query = Student::query();
        if ($className = $request->className) {
            $query->where('class_name', $className);
        }
        if ($group_name = $request->group_name) {
            $query->where('group_name', $group_name);
        }
        $students = $query->paginate(10);

        return response()->json(['data' => $students], 200);
    }

    public function store(Request $request)
    {
        $student = Student::create($request->all());
        return response()->json(['data' => $student], 200);
    }

    public function show(Student $student)
    {
        return response()->json(['data' => $student], 200);
    }

    public function update(Request $request, Student $student)
    {
        $student->update($request->all());
        return response()->json(['data' => $student], 200);
    }

    public function destroy(Student $student)
    {
        $student->delete();
        return response()->json(['data' => $student], 200);
    }
}
